package com.zhkj.shixi.tvplayer.adapter;

import android.content.Context;
import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.zhkj.shixi.tvplayer.R;


public class AudioAdapter extends ArrayAdapter<PlayList> {
    private  int resourceId;

    public AudioAdapter(@NonNull Context context, @LayoutRes int resource, @IdRes int textViewResourceId, @NonNull java.util.List objects) {
        super(context, resource, textViewResourceId, objects);
        resourceId=resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        PlayList playList=getItem(position);
        View view;
        ViewHoder viewHoder;
        if (convertView==null){
            view =LayoutInflater.from(getContext()).inflate(resourceId,parent,false);
            viewHoder =new ViewHoder();
            viewHoder.musicName =(TextView) view.findViewById(R.id.item_audiolist);
            view.setTag(viewHoder);
        }else {
            view =convertView;
            viewHoder =(ViewHoder)view.getTag();
        }
        viewHoder.musicName.setText(playList.getContent());
        return view;
    }
    class ViewHoder{
        TextView musicName;
    }
}
